package com.jdk.learn.thread;

/**
 * static修饰的存放在永久区  所以不存在多线程情况下独立数据问题
 */
public class TestStaticVisiable {
    private static   boolean flag=false;
    private static Integer num=1;

    static class ReadThread extends Thread{
        @Override
        public void run() {
            while (!flag){
                try {
                    Thread.sleep(500);
                    System.out.println("-------------------");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println(num);
        }
    }

    public void test(){
        new ReadThread().start();
        new ReadThread().start();
        new ReadThread().start();
        new ReadThread().start();
        new ReadThread().start();
        num=22;
        flag=true;
    }
    public static void main(String[] args) throws InterruptedException {
//        TestStaticVisiable testStaticVisiable=new TestStaticVisiable();
//        TestStaticVisiable testStaticVisiable2=new TestStaticVisiable();
//        Thread.sleep(1000);
//        testStaticVisiable.test();
//        testStaticVisiable2.test();
        new ReadThread().start();
        new ReadThread().start();
        Thread.sleep(500);
//        new ReadThread().start();
//        new ReadThread().start();
        num=22;
        flag=true;

    }
}
